package com.haozhen.rdd

/**
  * @author haozhen
  * @email haozh@ync1.com
  * @date 2021/1/30  16:26
  */

class MyClass1(x :Int){
  val num:Int = x
}

case class MyClass2(num:Int)

class MyClass3(x:Int) extends Serializable {
  val num:Int = x
}

object SerializableDemo {

  def main(args: Array[String]): Unit = {
    import org.apache.spark.rdd.RDD
    import org.apache.spark.{SparkConf, SparkContext}

    val conf: SparkConf = new SparkConf().setAppName(this.getClass.getCanonicalName().init).setMaster("local[*]")

    val sc = new SparkContext(conf)

    val rdd1: RDD[Int] = sc.parallelize(Array(1,2,3,4,5))

//    val o1 = new MyClass1(4)
    rdd1.cache()
    val o1 = new MyClass3(3)
    rdd1.map(x=>o1.num+x).collect().foreach(println)

    sc.stop()
  }
}
